package com.chapter14.Homework.homework02;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author 宋鑫宇
 * @version 1.0
 */
public class Homework02 {
    public static void main(String[] args) {
        ArrayList arrayList = new ArrayList();
        Car bmw = new Car("宝马", 400000);
        Car benz = new Car("奔驰", 500000);
        arrayList.add(bmw);
        arrayList.add(benz);
        arrayList.remove(bmw);
        System.out.println(arrayList.contains(benz));
        System.out.println(arrayList.size());
        System.out.println(arrayList.isEmpty());
        arrayList.clear();
        System.out.println(arrayList);
        ArrayList arrayList1 = new ArrayList();
        arrayList1.add(bmw);
        arrayList1.add(benz);
        arrayList.addAll(arrayList1);
        System.out.println(arrayList);
        System.out.println(arrayList.containsAll(arrayList1));
        arrayList.removeAll(arrayList1);
        System.out.println(arrayList);
        Iterator iterator = arrayList1.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println(next);
        }
        for (Object o : arrayList1) {
            System.out.println(o);
        }

    }
}

class Car{
    private String name;
    private double price;

    public Car(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Car{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}
